<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="baseurl" value="${pageContext.request.contextPath}/"></c:set>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="${baseurl}CSS/backMange.css">
<!-- 下拉 -->
<link rel="stylesheet" type="text/css"href="${baseurl}common/lowSelect/lib/css/htools.select.skin.css">
<!-- css资源 -->
<link rel="stylesheet" type="text/css" href="${baseurl}easyUI1.4.1/themes/default/easyui.css">
<!-- 图标资源 -->
<link rel="stylesheet" type="text/css" href="${baseurl}easyUI1.4.1/themes/icon.css">
<%-- <link rel="stylesheet" type="text/css" href="${baseurl}common/selectJs/example.css">
<link rel="stylesheet" type="text/css" href="${baseurl}common/selectJs/css/dropkick.css"> --%>
<script type="text/javascript" src="${baseurl}easyUI1.4.1/jquery.min.js"></script>
<!-- 下拉 -->
<script type="text/javascript" src="${baseurl}common/lowSelect/lib/js/jquery.htools.select.js"></script>
<!--EasyUI的js包 -->
<script type="text/javascript" src="${baseurl}easyUI1.4.1/jquery.easyui.min.js"></script>
<!-- 本地语言 -->
<script type="text/javascript" src="${baseurl}easyUI1.4.1/locale/easyui-lang-zh_CN.js"></script>

<script type="text/javascript" src="${baseurl}common/easySelect/jquery.cssforms.js"></script>
<%@ include file="/WEB-INF/JSP/ajax.jsp"%>
<script type="text/javascript">

//IE不支持console对象，此代码仅为测试使用
///////////////////////////////////////
window.console = window.console || (function () {
var c = {}; c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile  
= c.clear = c.exception = c.trace = c.assert = function () { };  
return c;  
})();  
$(function(){
    //创建DataGrid
    $("#handle_list_table").treegrid({
    	url:'${baseurl}DrivingSys/handle/alllist.action',
    	method:'post',          //请求方式
        idField:'easyID',           //定义标识树节点的键名字段
        treeField:'name',       //定义树节点的字段
        fit:true,               //网格自动撑满
        fitColumns:true,        //设置为 true，则会自动扩大或缩小列的尺寸以适应网格的宽度并且防止水平滚动。
        animate:true,//是否用动画效果
        striped:true,   //斑马线效果
        singleSelect:false,          //是否单选
        
        collapsible:false,//是否可折叠
        showFooter:false,//是否使用页脚
        columns:[[
      			 {field: 'ck', checkbox:true, width: '30' },  //复选框  
                 {field:'name',title:'名称',width:170,
      					formatter:function(value,row,index){
      	                    if(row.fisDelete == 1){
      	                    	value = '<span style="text-decoration:line-through;color:red">'+row.name+'</span>';
      	                    	return value;
      	                    }
      	         			else{
      	         				value = '<span >'+row.name+'</span>';
      	         				return value;
      	         			}                        
      	        		}
                  },
                  {field:'handleUrl',title:'操作路径',width:170,align:'left'},
                  
                  {field:'creatId',title:'创建人',width:50,align:'center'},
                  {field:'creatTime',title:'创建时间',width:125,align:'center'},
                  {field:'updateId',title:'修改人',width:50,align:'center'},
                  {field:'updateTime',title:'修改时间',width:125,align:'center'}, 
                  {field:'remark',title:'备注',width:100,align:'center'}
              ]],
              onBeforeExpand:function(node){
      	    		return;
	      	  },
	      	  onDblClick:function(node){
	      	  },
	      	  onLoadSuccess:function(){
	      			$('#handle_list_table').datagrid('clearSelections');
	      	  }
    });
    $("#Phandle_list_table").datagrid({
    	 url:'${baseurl}DrivingSys/handle/PhandleList.action',  //数据来源 
         //冻结列
            columns:[[
                {field: 'ck', checkbox: true, width: '30' },  //复选框  
                {field:'menuName',title:'菜单名称',width:150,align:'center'},
                {field:'menuUrl',title:'菜单路径',width:120,align:'center'},
                {field:'remark',title:'备注',width:150,align:'center'}
            ]],
            fitColumns:true,//自适应宽度，占满,不能和冻结列同时设置成true
            fit:true,//充满屏幕
            striped:true,   //斑马线效果
            idField:'id',    //主键列
            rownumbers:true,            //显示行号 
            singleSelect:true,          //是否单选
            //cache:false,				//关闭缓存
            method:'post',
            onLoadSuccess:function(){
            	$('#Phandle_list_table').datagrid('clearSelections');
                return false;
            },
	    	onClickRow : function(index, row){
				var selRow = $('#Phandle_list_table').datagrid('getSelections')[0];
	       	   $("#add_phandle_id").val(selRow.menuName);
	       	   $("#add_phandleID_id").val(selRow.id);
	       	 
	       	   $('#Phandle_window_div').window('close');
		   },loadMsg:'请稍候...'
    })
});
//////////////////////////////////////
</script>
</head>
<body style=" margin:0px;  overflow:hidden;">
	
	<table id="handle_list_table"toolbar="#tb">
	</table>
	<div id="tb"style="background-color: #f5f5f5;">
		<div style="background-color: #fff;border-radius:10px 10px 0 0;padding-top:10px;padding-left:10px">
			<table>
				<tr >
					<td >
							<label style="margin:5px 5px 0 10px ;font-size:14px;float:left">操作名称</label>
							<input type="text"  placeholder="操作名称" id="handle_name_id"
								style="width:60px;height:27px;margin-right:20px;margin-top: 5px;"/>
					</td>
					<td >
							<label style="margin:5px 5px 0 10px ;font-size:14px;float:left">所属菜单名称</label>
							<input type="text"  placeholder="所属菜单名称" id="handle_Pname_id"
								style="width:100px;height:27px;margin-right:20px;margin-top: 5px;"/>
					</td>
					<td  width="180px">
						<div style="float:left;margin:5px 5px 0 10px ;font-size:14px">是否可用</div>
						<select id="handle_fisdelete_id">
							<option value="no" selected>全部</option>
							<option value="0">是</option>
							<option value="1">否</option>
						</select>
					</td>
					<td>
						<input type="button"value="立即搜索" onclick="doSearch()"
							style="width:100px;height:32px;outline:none;border:none;background-image: url(${baseurl}images/myimages/button.jpg) ;background-position:0px -45px;cursor:pointer;color: #fff;border-radius:20px;padding:5px 21px"/>
					</td>
					<td></td>
				</tr>
				<tr>
					<shiro:hasPermission name="/handle/add.action">
					<td align="left">
						<div class="button_cz" onclick="add()">
							<table>
								<tr>
									<td><img src="${baseurl}images/myimages/xz.png"/></td>
									<td><div >新增</div></td>
								</tr>
							</table>
						</div>
					</td>
					</shiro:hasPermission>
					<shiro:hasPermission name="/handle/update.action">
					<td>
						<div class="button_cz" onclick="edit()">
							<table>
								<tr>
									<td><img src="${baseurl}images/myimages/xg.png"/></td>
									<td><div >修改</div></td>
								</tr>
							</table>
						</div>
					</td>
					</shiro:hasPermission>
					<shiro:hasPermission name="/handle/setdelete.action">
					<td>
						<div class="button_cz" onclick="setDelete('0')">
							<table>
								<tr>
									<td><img src="${baseurl}images/myimages/xg.png"/></td>
									<td><div >启用</div></td>
								</tr>
							</table>
						</div>
					</td>
					<td>
						<div class="button_cz" onclick="setDelete('1')">
							<table>
								<tr>
									<td><img src="${baseurl}images/myimages/xg.png"/></td>
									<td><div >停用</div></td>
								</tr>
							</table>
						</div>
					</td>
					</shiro:hasPermission>
					<td>
					</td>
				</tr>
			</table>
		</div>
	</div>
	<!-- 隐藏的添加窗口 -->
	<div id="add_window_div" class="easyui-window user_set_windows" title="添加操作" 
			data-options="modal:true,closed:true,iconCls:'icon-save',top:120" style="width:350px;height:390px;display:none">
		<div style="padding:5px 10px 0px 20px">
	    <form id="add_window_form" method="post"style="width:305px;height:270px">
	    	<table >
	    		<tr height="40px">
	    			<td width="30%" class="td_r"><b>*</b>操作名称:</td>
	        		<td width="70%" class="td_l">
	        			<input type="text" value=""id="add_name_id" />
	        			<input type="text"style="display:none"id="mnenu_id" />
	        		</td>
	    		</tr>
	    		<tr height="40px" >
	    			<td width="30%" class="td_r"><b>*</b>操作路径:</td>
	        		<td width="70%" class="td_l">
	        			<input type="text" value=""id="add_code_id" />
	        		</td>
	    		</tr>
	    		<tr height="40px" >
	    			<td width="30%" class="td_r">路径示例:</td>
	        		<td width="70%" class="td_l">
	        			<b>/user/add.action</b>
	        		</td>
	    		</tr>
	    		
	    		<tr id="add_trisdelete_id">
	    			<td width="30%" class="td_r">是否可用:</td>
	    			<td width="70%">
	    				<select class="all_select" id="add_isdelete_id">
	    					<option value="0">&nbsp;&nbsp;是&nbsp;&nbsp;</option>
							<option value="1">&nbsp;&nbsp;否&nbsp;&nbsp;</option>
						</select>
					</td>
	    		</tr>
	    		<tr height="40px"id="add_trPhandle_id" style="">
	    			<td width="30%" class="td_r">所属菜单:</td>
	        		<td width="70%" class="td_l">
	        			<input type="text" value=""id="add_phandle_id" onclick="opeanPhandle()"/>
	        			<input type="text" style="display:none"id="add_phandleID_id" />
	        		</td>
	    		</tr>
	    		<tr>
	    			<td width="30%" class="td_r">备注:</td>
	    			<td  width="70%" class="td_l">
	    			<textarea id="add_remark_id" style="width:100%;resize:none"></textarea>
	    			</td>
	    		</tr>
	    	</table>
	    </form>
	    <div style="text-align:center;padding:5px">
	    	<a href="javascript:void(0)" class="easyui-linkbutton"style="margin-right:100px;width:70px;height:30px;" onclick="submitForm()">提交</a>
	    	<a href="javascript:void(0)" class="easyui-linkbutton"style="width:70px;height:30px;" onclick="javascript:$('#add_window_div').window('close')">关闭</a>
	    </div>
	    </div>
	</div>

	<div id="Phandle_window_div" class="easyui-window user_set_windows" title="选择菜单" 
			data-options="modal:true,closed:true,iconCls:'icon-save',top:120" style="width:350px;height:210px;display:none">
			<table id="Phandle_list_table">
			</table>
	</div>
</body>
<script>
var $searchDeleteSelect = $("#handle_fisdelete_id");
/**
 * 初始化插件
 */
$searchDeleteSelect.goSelectInput({
    height: 30,
    width: 90
});
var handleHandFlag = '';
function opeanPhandle(){
	$('#Phandle_list_table').datagrid('clearSelections');
	$('#Phandle_list_table').datagrid('load');
	$("#Phandle_window_div").attr("style","width:350px;height:300px");
	$('#Phandle_window_div').window('open');
}
function add(){
	var menu = null;
	var thisBean = $('#handle_list_table').datagrid('getSelections');
	if( thisBean.length == 1){
		if( thisBean[0].easyID.indexOf('m') >= 0){
			menu = thisBean[0];
		}else{
			$('#handle_list_table').datagrid('clearSelections');
		}
	}else{
		$('#handle_list_table').datagrid('clearSelections');
	}
	handleHandFlag = 'add';
	//初始化
	$('#add_name_id').val("");
	$("#add_code_id").val("");
	//如果用户选择了父菜单 将其赋值到添加窗口
	if(menu!=null){
		$("#add_phandleID_id").val(menu.id);
		$("#add_phandle_id").val(menu.name);
	}else{
		$("#add_phandleID_id").val("");
		$("#add_phandle_id").val("");
	}
	$("#add_remark_id").val("");
	$("#add_trisdelete_id").val("");
	//隐藏
	$("#add_trPhandle_id").attr("style","");
	$("#add_trisdelete_id").attr("style","display:none");
    $('#add_window_div').panel({title: "添加操作"});
	$("#add_window_div").attr("style","width:350px;height:370px");
	$('#add_window_div').window('open');
}
function edit(){
	var thisBean = $('#handle_list_table').datagrid('getSelections');
	if( thisBean.length != 1){
		$.messager.alert('提示','请正确选择修改行!');
		return;
	}
	//easyid中含m的是菜单含h的是操作
	if( thisBean[0].easyID.indexOf('m') >= 0){
		$.messager.alert('提示','菜单不能修改!');
		$('#handle_list_table').datagrid('clearSelections');
		return;
	}
	var thisId = thisBean[0].id;
	handleHandFlag = 'update';
	$.ajax({
	      url:'${baseurl}DrivingSys/handle/handledata.action',  
	      type: "post",  
	      dataType:"json",
	      //timeout : 10000,
	      data:{"id":thisId}, 
	      success: function(json) {
	      	var handle = json.handle;
	      	$("#mnenu_id").val(handle.id);
	    	$('#add_name_id').val(handle.handleName);
	    	$("#add_code_id").val(handle.handleUrl);
	    	$("#add_phandle_id").val(handle.menuName);
	    	$("#add_phandleID_id").val(handle.menuId);
	    	$("#add_remark_id").val(handle.remark);
	    	$("#add_isdelete_id").val(handle.fisDelete);
	    	
	      },error:function(){
	      	$.messager.progress('close');
	      	$.messager.alert('提示','请刷新页面重试!','warning');
	      }
	  });
	
	//初始化
	$('#add_name_id').val("");
	$("#add_code_id").val("");
	$("#add_phandle_id").val("");
	$("#add_phandleID_id").val("");
	$("#add_remark_id").val("");
	$("#add_trisdelete_id").val("");
	//隐藏
	$("#add_trisdelete_id").attr("style","");
    $('#add_window_div').panel({title: "修改操作"});
	$("#add_window_div").attr("style","width:350px;height:370px");
	$('#add_window_div').window('open');
}
function checkStr(str){
	var patrn=/[!#@$%^&*()_+<>?:"{},\/;'[\]]/;
	if(patrn.test(str)){
		$.messager.alert('提示','请不要使用非中文符号!');
		return true;     
	}
	return false;
}
//分页查询
function doSearch(){
	//清除用户checked项
	$('#handle_list_table').datagrid('clearSelections');
	var handleName = $('#handle_name_id').val();
	var fisDelete = $searchDeleteSelect.val();
	var PhandleName = $('#handle_Pname_id').val();
	
	if(checkStr(handleName)||
			checkStr(PhandleName)){
		return;
	}
	//保留页码查询
	$('#handle_list_table').treegrid('reload',{
		menuName: PhandleName,
		name: handleName,
		isDelete: fisDelete
	});
}
//修改提交并验证表单
function submitForm(str){
	var id = $("#mnenu_id").val();
	var handleName = $('#add_name_id').val();
	var handleName = $('#add_name_id').val();
	var handleUrl = $('#add_code_id').val();
	var phandleID = $("#add_phandleID_id").val();
	var remark = $('#add_remark_id').val();
	var fisDelete = $("#add_isdelete_id").val();
	if(handleName ==null || handleName == "" ||
		handleUrl == null || handleUrl == ""){
		$.messager.alert('提示','操作名称与路径必须填写!');
		return;
	}
	var patrn=/(\/\w+)+/;
	if(!patrn.test(handleUrl)){
		$.messager.alert('提示','路径不符合要求!');
		return true;     
	}
	if(checkStr(handleName)||checkStr(remark)){
		return;
	}
	// /user/add.action
	
	if(phandleID == null || phandleID == ""){
		$.messager.alert('提示','单击选择父操作!');
		return;
	}
	if(fisDelete == null || fisDelete == ""){
		fisDelete = 0;
	}
	var url = '${baseurl}DrivingSys/handle/'+handleHandFlag+'.action';
	var data = {"id":id*1,"handleName":handleName,"handleUrl":handleUrl,
				"menuId":phandleID,
				"fisDelete":fisDelete,"remark":remark};
	$.ajax({
	      url:url,  
	      type: "post",  
	      dataType:"json",
	      //timeout : 10000,
	      data:data, 
	      success: function(json) {
	    	  console.log(json);
	    	  if(json.success <=0 ){
		        	$.messager.alert('提示','操作失败，请刷新页面重试!','warning');
	        	}else{
		        	$.messager.show({
						title:'提示',
						msg:'设置成功!',
						timeout:3000,
						showType:'slide'
					});
		        	$('#add_window_div').window('close')
		        	doSearch();
	        	}
	      },error:function(){
	      	$.messager.progress('close');
	      	$.messager.alert('提示','请刷新页面重试!','warning');
	      }
	  });
}	
//启用停用
function setDelete(isDelete){
		var selRow = $('#handle_list_table').datagrid('getSelections') ;
		if (selRow.length==0) {
	      $.messager.alert("提示", "请选择要操作的行！", "info");  
	      return;  
    	}
		var ids="";  
		var messageMenu = false;
		//批量获取选中行的评估模板ID  
	    for (i = 0; i < selRow.length;i++) {
	    	//如果是菜单跳过
	    	if( selRow[i].easyID.indexOf('m') >= 0){
	    		messageMenu = true;
	    		continue;
			}
	    	//如果该行已为此状态跳过
		  	if(isDelete == '0'&& selRow[i].fisDelete == '0'){
		  		continue;
		  	}
		  	if(isDelete == '1'&& selRow[i].fisDelete == '1'){
		  		continue;
		  	}
		    if (ids =="") {  
		      	ids = selRow[i].id;  
		    } else {
		      	ids = selRow[i].id +"," + ids;  
		    }      
	    }  
		if(ids == ""){
			if(messageMenu){
				$.messager.alert("提示", "菜单状态不可修改！", "info"); 
			  	return;
			}
		  	$.messager.alert("提示", "选中的可设置操作必须大于一！", "info"); 
		  	return;
		}
		$.messager.confirm('提示', '是否继续操作?', function (r) {
		      if (!r) {
		    	  $.messager.progress('close');
		           return;  
		      }
				$.ajax({
			        url:'${baseurl}DrivingSys/handle/setdelete.action',  
			        type: "post",  
			        dataType:"json",
				    data:{"ids":ids,"isDelete":isDelete}, 
			        success: function(json) {
			        	if(json.success == undefined || json.success == 'undefined'){
				        	$.messager.alert('提示','操作失败，请刷新页面重试!','warning');
			        	}else{
				        	$.messager.show({
								title:'提示',
								msg:'设置成功!',
								timeout:3000,
								showType:'slide'
							});
				        	doSearch();
			        	}
			        },error:function(){
			        	$.messager.progress('close');
			        	$.messager.alert('提示','操作失败，请刷新页面重试!','warning');
			        }
			    })
		});
}
</script>
</html>